package com.course.domain.dto;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.course.domain.pojo.CourseComment;
import com.course.domain.pojo.UserInfo;
import com.course.domain.vo.CourseCommentVo;
import lombok.Data;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import java.util.*;

@Data
@ToString
public class CourseCommentDto extends CourseComment {
    // 子评论
    private List<CourseCommentDto> childList;
    // 评论用户头像
    private String avatar;
    // 评论用户名
    private String username;
    // 被回复用户名
    private String targetUsername;

    public static CourseCommentDto createCourseCommentDto(CourseComment courseComment) {
        CourseCommentDto courseCommentDto = new CourseCommentDto();
        BeanUtils.copyProperties(courseComment, courseCommentDto);
        courseCommentDto.setChildList(new ArrayList<>());
        return courseCommentDto;
    }

    public static CourseCommentDto convertCourseCommentDtoByMap(Map<Object, Object> map) {
        CourseCommentDto bean = BeanUtil.mapToBean(map, CourseCommentDto.class, false, CopyOptions.create()
                .ignoreNullValue()
                .ignoreError()
                .setEditable(CourseComment.class));
        bean.setChildList(new ArrayList<>());
        return bean;
    }

}

